﻿using System;
using UnityEngine;
using UnityEngine.U2D;

namespace Framework
{
    public class ViewLoader : ViewEvent
    {
        protected ILoader _resLoader;
        
        public string modulePath { get; protected set; }

        public GameObject LoadGameObject(string path, bool instantiate = false)
        {
            return _resLoader.LoadGameObject(path, instantiate);
        }

        public void LoadGameObjectAsync(string path, Action<GameObject> onComplete, bool instantiate)
        {
            _resLoader.LoadGameObjectAsync(path, onComplete, instantiate);
        }

        public Sprite LoadSprite(string path)
        {
            return _resLoader.LoadSprite(path);
        }

        public Texture LoadTexture(string path)
        {
            return _resLoader.LoadTexture(path);
        }

        public void LoadSpriteAtlas(string path, Action<SpriteAtlas> onComplete)
        {
            _resLoader.LoadSpriteAtlas(path, onComplete);
        }

        public Sprite GetAtlasSprite(string assetName)
        {
            return _resLoader.GetAtlasSprite(assetName);
        }

        public void UnloadAsset(string path, bool unloadDependencies = false)
        {
            _resLoader.UnloadAsset(path, unloadDependencies);
        }

        public void UnloadAllAsset()
        {
            _resLoader.UnloadAllAsset();
        }

        public string LoadText(string path)
        {
            return _resLoader.LoadText(path);
        }

        public override void Dispose()
        {
            base.Dispose();
            //TODO:移除加载的资源
        }
    }
}